﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
using Lilium.Web.Mvc.State;

namespace Lilium.Web.Mvc.Html
{
	public static class FormExtensions
	{
		public static MvcForm BeginForm(this HtmlHelper html, IDictionary<string, object> routeValues)
		{
			if (html == null) throw new ArgumentNullException("html");

			var routeValueDictionary = new RouteValueDictionary(routeValues);

			var stateService = html.GetService<IStateService>(false);
			if (stateService != null)
			{
				stateService.SaveObjectsState(routeValues);
			}

			return System.Web.Mvc.Html.FormExtensions.BeginForm(html, routeValueDictionary);
		}
	}
}